﻿<storeControls:StoreApplicationPage x:Class="Store.WP7.Views.CheckoutView"
                                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                                    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                                    xmlns:storeControls="clr-namespace:Store.WP7.Controls;assembly=Store.WP7.Controls"
                                    xmlns:behaviors="clr-namespace:Store.WP7.Framework.Interactions;assembly=Store.WP7.Framework"
                                    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                                    xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
                                    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                                    FontFamily="{StaticResource PhoneFontFamilyNormal}"
                                    FontSize="{StaticResource PhoneFontSizeNormal}"
                                    Foreground="{StaticResource PhoneForegroundBrush}"
                                    SupportedOrientations="PortraitOrLandscape"
                                    Orientation="Portrait"
                                    mc:Ignorable="d"
                                    d:DesignHeight="768"
                                    d:DesignWidth="480"
                                    DataContext="{Binding CheckoutViewModel, Source={StaticResource ViewModelLocator}}">

    <i:Interaction.Behaviors>
        <behaviors:SystrayBehavior SystrayOpacity="0.5"
                                   IsBusy="{Binding IsBusy}"
                                   BusyMessage="{Binding BusyMessage}" />
    </i:Interaction.Behaviors>

    <Grid x:Name="LayoutRoot">

        <Image Stretch="None" 
               Source="/Assets/Images/PageBackground.png"
               HorizontalAlignment="Left"/>
        
        <Grid x:Name="ContentPanel"
              Margin="12,150,12,0">

            <ScrollViewer>
                <Grid>
                    <!-- Checkout + récapitulatif -->
                    <StackPanel Margin="12,0">
                        <i:Interaction.Behaviors>
                            <behaviors:BoolValueVisibilityBehavior Value="{Binding WantToAddNewAddress}"
                                                                   Negate="True" />
                        </i:Interaction.Behaviors>

                        <Button Content="Ajouter addresse"
                                Grid.Row="1"
                                Margin="0,6,0,6"
                                Style="{StaticResource ButtonStyle}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ec:CallMethodAction MethodName="OnGoToCreateAddress"
                                                         TargetObject="{Binding Mode=OneWay}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                        <toolkit:ListPicker x:Name="lstPickerAddress"
                                            Header="Mes adresses"
                                            ItemsSource="{Binding Addresses}"
                                            SelectedIndex="{Binding PickerSelectedIndex, Mode=TwoWay}" Margin="0,12">
                            <toolkit:ListPicker.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Border Background="YellowGreen"
                                                Width="50"
                                                Height="50"
                                                Margin="5">
                                        </Border>
                                        <StackPanel Orientation="Vertical">
                                            <TextBlock Text="{Binding Label}"
                                                       Width="150"
                                                       FontWeight="Bold"
                                                       Margin="-12,0,0,0" />
                                            <TextBlock Style="{StaticResource PhoneTextSmallStyle}">
                          <Run Text="{Binding Street}" />
                          <Run Text="{Binding ZipCode}" />
                          <Run Text="{Binding City}" />
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                </DataTemplate>
                            </toolkit:ListPicker.ItemTemplate>
                        </toolkit:ListPicker>
                        <ItemsControl ItemsSource="{Binding Products}"
                                      ItemTemplate="{StaticResource ProductSummaryDataTemplate}" Margin="-24,12" />
                        <Border x:Name="TotalGrid"
                        	Margin="0"
                        	Background="{StaticResource AccentBrushLight}"
                        	Padding="12" Height="94">
                        	<Grid>
                        		<Grid.ColumnDefinitions>
                        			<ColumnDefinition Width="Auto" />
                        			<ColumnDefinition Width="12" />
                        			<ColumnDefinition Width="*" />
                        		</Grid.ColumnDefinitions>
                        		<Grid.RowDefinitions>
                        			<RowDefinition Height="Auto" />
                        			<RowDefinition Height="12" />
                        			<RowDefinition Height="*" />
                        		</Grid.RowDefinitions>
                            
                        		<TextBlock Style="{StaticResource PhoneTextNormalStyle}"
                        			Foreground="{StaticResource ForegroundBrush}"
                        			TextWrapping="Wrap"
                        			Text="Frais Livraison"
                        			Margin="0" 
                        			Grid.Row="0" Grid.Column="0"/>
                        		<TextBlock Style="{StaticResource PhoneTextTitle3Style}"
                        			Foreground="{StaticResource ForegroundBrush}"
                        			FontFamily="Segoe WP Black"
                        			TextWrapping="Wrap"
                        			Text="MONTANT TOTAL"
                        			Margin="0"
                        			Grid.Row="2" Grid.Column="0" />
                            
                        		<TextBlock Style="{StaticResource PhoneTextNormalStyle}"
                        			Foreground="{StaticResource ForegroundBrush}"
                        			TextWrapping="Wrap"
                        			Text="0 €"
                        			Margin="0"
                        			HorizontalAlignment="Right"
                        			Grid.Row="0"
                        			Grid.Column="2" />
                        		<TextBlock Style="{StaticResource PhoneTextTitle3Style}"
                        			Foreground="{StaticResource ForegroundBrush}"
                        			FontFamily="Segoe WP Black"
                        			TextWrapping="Wrap"
                        			Text="{Binding TotalPrice}"
                        			Margin="0"
                        			HorizontalAlignment="Right"
                        			Grid.Row="2"
                        			Grid.Column="2" />
                        	</Grid>
                        </Border>

                        <Button Content="Valider commande"
                                Grid.Row="1"
                                Margin="0,12,0,6"
                                Style="{StaticResource ButtonImportantStyle}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ec:CallMethodAction MethodName="OnSubmitOrder"
                                                         TargetObject="{Binding Mode=OneWay}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>

                    </StackPanel>

                    <!-- Address -->
                    <StackPanel Visibility="Collapsed">
                        <i:Interaction.Behaviors>
                            <behaviors:BoolValueVisibilityBehavior Value="{Binding WantToAddNewAddress}" />
                        </i:Interaction.Behaviors>

                        <TextBlock Text="Libellé adresse"
                                   Style="{StaticResource PhoneTextNormalStyle}" />
                        <TextBox Text="{Binding NewAddress.Label, Mode=TwoWay}" />
                        
                        <TextBlock Text="Nom"
                                   Style="{StaticResource PhoneTextNormalStyle}" />
                        <TextBox Text="{Binding NewAddress.LastName, Mode=TwoWay}"
                                 InputScope="PersonalSurname" />
                        
                        <TextBlock Text="Prénom"
                                   Style="{StaticResource PhoneTextNormalStyle}" />
                        <TextBox Text="{Binding NewAddress.FirstName, Mode=TwoWay}"
                                 InputScope="PersonalSurname" />
                        
                        <TextBlock Text="Rue"
                                   Style="{StaticResource PhoneTextNormalStyle}" />
                        <TextBox Text="{Binding NewAddress.Street, Mode=TwoWay}"
                                 InputScope="AddressStreet" />
                        
                        <TextBlock Text="Code Postal"
                                   Style="{StaticResource PhoneTextNormalStyle}" />
                        <TextBox Text="{Binding NewAddress.ZipCode, Mode=TwoWay}"
                                 InputScope="Number" />
                        
                        <TextBlock Text="Ville"
                                   Style="{StaticResource PhoneTextNormalStyle}" />
                        <TextBox Text="{Binding NewAddress.City, Mode=TwoWay}"
                                 InputScope="AddressCity" />
                        
                        <TextBlock Text="Téléphone"
                                   Style="{StaticResource PhoneTextNormalStyle}" />
                        <TextBox Text="{Binding NewAddress.Phone, Mode=TwoWay}"
                                 InputScope="TelephoneNumber" />

                    </StackPanel>

                </Grid>
            </ScrollViewer>
        </Grid>

        <storeControls:BindableApplicationBar IsVisible="{Binding WantToAddNewAddress}"
                                              IsMenuEnabled="True">
            <storeControls:BindableApplicationBarIconButton IconUri="/icons/appbar.favs.rest.png"
                                                            Text="auto-rempli">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ec:CallMethodAction MethodName="OnAutoFillAddress"
                                             TargetObject="{Binding Mode=OneWay}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </storeControls:BindableApplicationBarIconButton>
            <storeControls:BindableApplicationBarIconButton IconUri="/icons/appbar.save.rest.png"
                                                            Text="sauver">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ec:CallMethodAction MethodName="OnCreateAndSetAddress"
                                             TargetObject="{Binding Mode=OneWay}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </storeControls:BindableApplicationBarIconButton>
            <storeControls:BindableApplicationBarIconButton IconUri="/icons/appbar.cancel.rest.png"
                                                            Text="annuler">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ec:CallMethodAction MethodName="OnCancelCreateAddress"
                                             TargetObject="{Binding Mode=OneWay}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </storeControls:BindableApplicationBarIconButton>
        </storeControls:BindableApplicationBar>

    </Grid>

</storeControls:StoreApplicationPage>